if (SERVER) then
	AddCSLuaFile("shared.lua")
end

if (CLIENT) then
	SWEP.Slot				= 4
	SWEP.SlotPos			= 5
	SWEP.ViewModelFOV		= 60
	SWEP.ViewModelFlip		= false
	SWEP.IconLetter			= "i"

	surface.CreateFont("HalfLife2", ScreenScale(60), 500, true, true, "HL2SelectIcons")
	killicon.AddFont("shot_guidedmissle", "HL2MPTypeDeath", "3", Color(100, 100, 100, 255))
end
	
SWEP.Base				= "weapon_cs_base"
SWEP.HoldType			= "rpg"

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= false

SWEP.PrintName = "Guided Missle"

SWEP.ViewModel = "models/weapons/v_rpg.mdl"
SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl"
SWEP.ViewModelFOV = 54

SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false

SWEP.Primary.Ammo = "none"
SWEP.Secondary.Ammo = "none"

function SWEP:Initialize()
    util.PrecacheSound("weapons/rpg/rocketfire1.wav")
    self:SetWeaponHoldType("rpg")
end

function SWEP:PrimaryAttack()
	if(CLIENT) then return end
	if ValidEntity(self.Owner.Rocket) then return end
    if self.Owner:WaterLevel() >= 2 then return end
    local missle = ents.Create("shot_guidedmissle")
	missle:SetOwner(self.Owner)
	missle:SetPos(self.Owner:GetPos()+(self.Owner:GetForward()*40)+Vector(0,0,36))
    missle:SetAngles(self.Owner:GetAngles())
    missle:SetVar("Owner",self.Owner)
    missle:Spawn()
	self.Owner.Rocket = missle
	self.Weapon:EmitSound("weapons/rpg/rocketfire1.wav")
    self.Owner:SetViewEntity(missle)
    self.Owner:SetMoveType(MOVETYPE_NONE)
	self:Remove()
end

function SWEP:SecondaryAttack() 
end

function SWEP:Reload()
end
function SWEP:DrawWeaponSelection(x, y, wide, tall, alpha)
	draw.SimpleText(self.IconLetter, "HL2SelectIcons", x + wide/2, (y + tall*0.2)-10, Color(255, 210, 0, 255), TEXT_ALIGN_CENTER)
	if(self:GetUpgrade() > 0) then
		draw.SimpleText("K", "CSKillIcons", x + wide-20, y + tall-25, Color(200,200, 200, 255), TEXT_ALIGN_CENTER)
	end
end